﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace Common.Core.Configuration
{
	public class DefaultNamedElementCollection<ItemType> : NamedElementCollection<ItemType> where ItemType : NamedConfigurationElement, new()
	{
		[ConfigurationProperty( DefaultNameName, DefaultValue = null, IsRequired = true, IsKey = false )]
		public string DefaultName
		{
			get { return (string)this[DefaultNameName]; }
			set { this[DefaultNameName] = value; }
		}	const string DefaultNameName = "defaultName";

		public ItemType GetSelected()
		{
			return Get( DefaultName );
		}

		public ItemType GetItem( string name )
		{
			return Get( name ) ?? GetSelected();
		}
	}
}
